﻿using System;
using System.ComponentModel;

namespace Wala.Connection.Objects.Timeline
{
    public abstract class TimelineInfo : INotifyPropertyChanged
    {
        #region //--------- Private Fields --------------//

        private long _id;

        private int _owner_Id;
        private long _owner_Avatar_Id;
        private long _owner_Cover_Id;
        private string _owner_Display_Name;

        private string _location_Text;
        private double _location_X;
        private double _location_Y;

        private int _total_Comments;
        private int _total_Likes;
        private int _total_Shares;
        private int _total_Tags;

        private long _time_Stamp;

        private bool _is_User_Like;
        private bool _is_User_Tag;
        private bool _is_User_Follow;

        public event PropertyChangedEventHandler PropertyChanged;
        #endregion

        #region //--------- Public Constructors ---------//

        public TimelineInfo()
        {
        }

        public TimelineInfo(int ownerId, long ownerAvatarId, long ownerCoverId, string ownerDisplayName,
            string locationText, double locationX, double locationY, int totalComments, int totalLikes,
            int totalShares, long timeStamp, bool isUserLike, bool isUserTag, bool isUserFollow)
        {


            _owner_Id = ownerId;
            _owner_Avatar_Id = ownerAvatarId;
            _owner_Cover_Id = ownerCoverId;
            _owner_Display_Name = ownerDisplayName;

            _location_Text = locationText;
            _location_X = locationX;
            _location_Y = locationY;

            _total_Comments = totalComments;
            _total_Likes = totalLikes;
            _total_Shares = totalShares;

            _time_Stamp = timeStamp;

            _is_User_Like = isUserLike;
            _is_User_Tag = isUserTag;
            _is_User_Follow = isUserFollow;
        }

        #endregion

        #region //--------- CLR Properties --------------//
        /// <summary>
        /// Gets or sets the is user follow.
        /// </summary>
        /// <value>The is user follow.</value>
        public bool User_Follow
        {
            get
            {
                return _is_User_Follow;
            }
            set
            {

                if (_is_User_Follow != value)
                {
                    _is_User_Follow = value;
                    OnPropertyChanged("User_Follow");
                }
            }
        }

        /// <summary>
        /// Gets or sets the is user like.
        /// </summary>
        /// <value>The is user like.</value>
        public bool User_Like
        {
            get
            {
                return _is_User_Like;
            }
            set
            {

                if (_is_User_Like != value)
                {
                    _is_User_Like = value;
                    OnPropertyChanged("User_Like");

                    if (_is_User_Like)
                    {
                        this.User_Follow = true;
                    }

                }
            }
        }

        /// <summary>
        /// Gets or sets the is user tag.
        /// </summary>
        /// <value>The is user tag.</value>
        public bool User_Tag
        {
            get
            {
                return _is_User_Tag;
            }
            set
            {

                if (_is_User_Tag != value)
                {
                    _is_User_Tag = value;
                    OnPropertyChanged("User_Tag");
                }

            }
        }

        /// <summary>
        /// Gets or sets the time stamp.
        /// </summary>
        /// <value>The time stamp.</value>
        public long Time_Stamp
        {
            get
            {
                return _time_Stamp;
            }
            set
            {

                if (_time_Stamp != value)
                {
                    _time_Stamp = value;
                    OnPropertyChanged("Time_Stamp");
                }

            }
        }

        /// <summary>
        /// Gets or sets the total shares.
        /// </summary>
        /// <value>The total shares.</value>
        public int Number_Of_Shares
        {
            get
            {
                if (_total_Shares < 0)
                {
                    return 0;
                }
                else
                {
                    return _total_Shares;
                }
            }
            set
            {

                if (_total_Shares != value)
                {
                    _total_Shares = value;
                    OnPropertyChanged("Number_Of_Shares");
                }

            }
        }

        /// <summary>
        /// Gets or sets the total likes.
        /// </summary>
        /// <value>The total likes.</value>
        public int Number_Of_Likes
        {
            get
            {
                if (_total_Likes < 0)
                {
                    return 0;
                }
                else
                {
                    return _total_Likes;
                }
            }
            set
            {

                if (_total_Likes != value)
                {
                    _total_Likes = value;
                    OnPropertyChanged("Number_Of_Likes");
                }

            }
        }

        /// <summary>
        /// Gets or sets the total comments.
        /// </summary>
        /// <value>The total comments.</value>
        public int Number_Of_Comments
        {
            get
            {
                if (_total_Comments < 0)
                {
                    return 0;
                }
                else
                {
                    return _total_Comments;
                }
            }
            set
            {

                if (_total_Comments != value)
                {
                    _total_Comments = value;
                    OnPropertyChanged("Number_Of_Comments");
                }

            }
        }

        /// <summary>
        /// Gets or sets the number_ of_ tags.
        /// </summary>
        /// <value>The number_ of_ tags.</value>
        [Obsolete("Dont use this", true)]
        public int Number_Of_Tags
        {
            get
            {
                if (_total_Tags < 0)
                {
                    return 0;
                }
                else
                {
                    return _total_Tags;
                }
            }
            set
            {

                if (_total_Tags != value)
                {
                    _total_Tags = value;
                    OnPropertyChanged("Number_Of_Tags");
                }
            }
        }

        /// <summary>
        /// Gets or sets the location Y.
        /// </summary>
        /// <value>The location Y.</value>
        public double Location_Y
        {
            get
            {
                return _location_Y;
            }
            set
            {

                if (_location_Y != value)
                {
                    _location_Y = value;
                    OnPropertyChanged("Location_Y");
                }

            }
        }

        /// <summary>
        /// Gets or sets the location X.
        /// </summary>
        /// <value>The location X.</value>
        public double Location_X
        {
            get
            {
                return _location_X;
            }
            set
            {

                if (_location_X != value)
                {
                    _location_X = value;
                    OnPropertyChanged("Location_X");
                }

            }
        }

        /// <summary>
        /// Gets or sets the location text.
        /// </summary>
        /// <value>The location text.</value>
        public string Location_Text
        {
            get
            {
                return _location_Text;
            }
            set
            {

                if (_location_Text != value)
                {
                    _location_Text = value;
                    OnPropertyChanged("Location_Text");
                }

            }
        }

        /// <summary>
        /// Gets or sets the display name of the owner.
        /// </summary>
        /// <value>The display name of the owner.</value>
        public string Owner_Display_Name
        {
            get
            {
                return _owner_Display_Name;
            }
            set
            {

                if (_owner_Display_Name != value)
                {
                    _owner_Display_Name = value;
                    OnPropertyChanged("Owner_Display_Name");
                }

            }
        }

        /// <summary>
        /// Gets or sets the owner cover id.
        /// </summary>
        /// <value>The owner cover id.</value>
        public long Owner_Cover_Id
        {
            get
            {
                return _owner_Cover_Id;
            }
            set
            {

                if (_owner_Cover_Id != value)
                {
                    _owner_Cover_Id = value;
                    OnPropertyChanged("Owner_Cover_Id");
                }

            }
        }

        /// <summary>
        /// Gets or sets the owner avatar id.
        /// </summary>
        /// <value>The owner avatar id.</value>
        public long Owner_Avatar_Id
        {
            get
            {
                return _owner_Avatar_Id;
            }
            set
            {

                if (_owner_Avatar_Id != value)
                {
                    _owner_Avatar_Id = value;
                    OnPropertyChanged("Owner_Avatar_Id");
                }

            }
        }

        /// <summary>
        /// Gets or sets the owner id.
        /// </summary>
        /// <value>The owner id.</value>
        public int Owner_Id
        {
            get
            {
                return _owner_Id;
            }
            set
            {

                if (_owner_Id != value)
                {
                    _owner_Id = value;
                    OnPropertyChanged("Owner_Id");
                }
            }
        }

        public abstract long Id { get; set; }

        public abstract int Type { get; }

        #endregion

        #region //--------- Public Methods --------------//
        /// <summary>
        /// Compares two PhotoInfo object.
        /// </summary>
        /// <param name="another">Another PhotoInfo object.</param>
        /// <returns></returns>
        public int CompareTo(PhotoInfo another)
        {
            if (another.Time_Stamp > this.Time_Stamp)
                return 1;

            if (another.Time_Stamp < this.Time_Stamp)
                return -1;

            return 0;
        }
        #endregion

        #region //----------- Private Methods ---------//

        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion
    }
}
